<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="support.*,java.util.*,java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Provide degrees - Choose discipline</title>
</head>
<body>
	<%
		Student student = (Student)session.getAttribute("student");
		Degree degree = (Degree)session.getAttribute("degree");
		ArrayList<Degree> degreeList = (ArrayList<Degree>)session.getAttribute("degreelist");

		String newUniversity = request.getParameter("newuniversity");
		if(newUniversity != null)
		{
			degree.newUniversity(newUniversity);
			degree.university(-1);
		}
		else
		{
			degree.university(Integer.parseInt(request.getParameter("university")));
			degree.newUniversity("");
		}
	%>
	
	<h3>Previously entered in information:</h3>

	<p><%= "Full name: " + student.getFirstName() + " " + student.getMiddleName() + " " + student.getLastName() %></br>
	<%= "Country of Citizenship: " + student.getCitizenshipName() %></br>
	<% if (student.getState() != "") { %>
		<%= "Address: " + student.getAddress() + ", " + student.getCity() + " " + student.getState() + ", " + student.getZipcode() %>
	<% } else {%>
		<%= "Address: " + student.getAddress() + ", " + student.getCity() + ", " + student.getZipcode() %></p>
	<% } %>
	<p><b>Current Degree:</b><br>
	Location: <%= degree.getLocationName() %><br>
	University: <%= degree.getUniversityName() %><br/>
	</p>
	
	<%
   //Print out degree information if coming from more degrees
   if (degreeList != null) {
      for (int i = 0; i < degreeList.size(); i++) {
%>
         <p><b><%= "Degree #" + (i+1) + ": " %></b><br>
         <%= degreeList.get(i).getDisciplineName() + ", " + degreeList.get(i).getTitle() %><br> 
         <%= degreeList.get(i).getUniversityName() %><br>
         <%= degreeList.get(i).getLocationName() %><br>
         <%= "Year of Graduation: " + degreeList.get(i).getDate() %><br>
         <%= "GPA: " + degreeList.get(i).getGpa() %><br>
<%
	   }	   
   }
 
	Connection conn = null;
	PreparedStatement stm = null;
	ResultSet result = null;

	try {
	Class.forName("org.postgresql.Driver");
	conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/Graduate_application_database", "postgres", "postgres");
	conn.setAutoCommit(false);
	stm = conn.prepareStatement("SELECT * FROM disciplines ");
	result = stm.executeQuery();
	conn.commit();
	conn.setAutoCommit(true);
%>
	
	<form method="GET" action="degreeList.jsp">
		Choose Your Degree:<br/>
			<%while(result.next()){ %>
			<input type = "radio" name = "discipline" value = <%= result.getInt("d_id") %> />
				<%= result.getString("discipline") %>
			<br/>
			<%} %>
		
		Or Enter A New One: <input type="text" name ="otherdegree" /><br/>
		Date Received: <input type="text" name ="date" /> (mm/yyyy)<br/>
		GPA: <input type = "text" name = "gpa" /><br/>
		<select name = "title">
			<option>BS</option>
			<option>MS</option>
			<option>PHD</option>
		</select><br/>
		<input type ="submit" name="submit"/>
	
	</form>
<%
	result.close();
	stm.close();
	conn.close();
}
catch (Exception e)
{
	throw new RuntimeException(e);
}
finally {
   if (result != null) {
       try {
           result.close();
       } 
       catch (SQLException e) { }
       result = null;
   }
   if (stm != null) {
       try {
           stm.close();
       } 
       catch (SQLException e) { }
       stm = null;
   }
   if (conn != null) {
       try {
           conn.close();
       } 
       catch (SQLException e) { }
       conn = null;
   }
}
%>

</body>
</html>